<%@ page language="java"  pageEncoding="UTF-8"%>
<%@ include file="/views/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>试用区-券码批量生成</title>
	<link rel="stylesheet" href="<%=path%>/css/bootstrap/3.3.5/css/bootstrap.min.css" />
	<link rel="stylesheet" href="<%=path%>/css/cropper.min.css" />
	<link rel="stylesheet" href="<%=path%>/css/cz.css" />
	<script src="<%=path%>/js/jquery-1.11.0.min.js"></script>
	<script src="<%=path%>/js/plugins/layer/layer.js"></script>
<body class="gray-bg">
<jsp:include page="/views/commons/header.jsp"></jsp:include>
<div class="container page-single">
	<div class="col-md-12">
		<div class="panel panel-default">
			<div class="panel-heading">
				<h3 class="panel-title">券码批量生成</h3>
			</div>
			<div class="panel-body event-create">

				<form class="form-horizontal" id="coupon_form" action="javascript:insertGoods()">
					<div class="form-group">
						<label  class="col-sm-1 control-label">
							券码名称 <em>*</em>
						</label>
						<div class="col-sm-10">
							<input class="form-control event-create-form-control-block" maxlength="50" minlength="1" 
							name="couponName" id="coupon_name" placeholder="券码名称" type="text" value="${coupon.couponName}">
						</div>
					</div>
					<div class="form-group">
						<label  class="col-sm-1 control-label">
							生成的数量 <em>*</em>
						</label>
						<div class="col-sm-10">
							<input class="form-control event-create-form-control-block" maxlength="4" minlength="1" 
							name="couponNum" placeholder="生成的数量（最多一次5000个）" type="text" value="${coupon.couponNum}">
						</div>
					</div>
					<div class="form-group">
						<label  class="col-sm-1 control-label">
							批次号<em>*</em>
						</label>
						<div class="col-sm-5">
							<input class="form-control event-create-form-control-block" maxlength="15" minlength="1" 
							name="couponBatch" id="coupon_batch" placeholder="批次号（数字，字母都可以，不要重复）" type="text" value="${coupon.couponBatch}">
						</div>
						<label  class="col-sm-1 control-label">
							券码前缀(2位字母)<em>*</em>
						</label>
						<div class="col-sm-5">
							<input class="form-control event-create-form-control-block" maxlength="2" minlength="1" 
							name="couponPre" placeholder="券码前缀(2位字母，不能重复)" type="text" value="${coupon.couponPre}">
						</div>
					</div>
					
					<d:radio describe="券码类型" tableColumn="application_scope" fieldName="applicationScope" value="${coupon.applicationScope}" queryFunction="scopeClick"/>
					
					<div class="form-group" id="goods_name_div">
						<label  class="col-sm-1 control-label">
							适用商品名称<em>*</em>
						</label>
						<div class="col-sm-10">
							<input class="form-control event-create-form-control-block" maxlength="400"  id="goods_name_input"
							name="applicationGoodsName" placeholder="适用商品名称" type="text" value="${coupon.applicationGoodsName}">
						</div>
					</div>
					
					<div class="form-group" >
						<label  class="col-sm-1 control-label">
							加收邮费金额
						</label>
						<div class="col-sm-10">
							<input class="form-control event-create-form-control-block" maxlength="10" 
							name="extraFee" placeholder="加收邮费金额，12元基础上加收的邮费" type="text" value="${coupon.extraFee}">
						</div>
					</div>
					
					<div class="form-group">
						<label  class="col-sm-1 control-label">
							获取途径说明
						</label>
						<div class="col-sm-10">
							<input class="form-control event-create-form-control-block" maxlength="400" 
							name="acquiringWay" placeholder="获取途径说明 " type="text" value="${coupon.acquiringWay}">
						</div>
					</div>
					
					<div class="form-group">
						<div class="col-sm-offset-1 col-sm-10">
							<button type="submit" class="btn btn-primary" id="coupon_confirm_btn">生成券码并导出</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
<jsp:include page="/views/commons/footer.jsp"></jsp:include>

<script type="text/javascript">
	function insertGoods(){
		$("#coupon_confirm_btn").addClass("disabled").attr("disabled","disabled").val("提交中");
		$.ajax({
			url : path + "/admin/coupon/create",
			type : "post",
			dataType : "json",
			data : $("#coupon_form").serialize(),
			success : function(data)
			{
				if(data.result){
					layer.msg(data.message,{icon: 1});
					$("#coupon_confirm_btn").removeClass("disabled").removeAttr("disabled").val("生成券码并导出");
				}else{
					layer.msg(data.message,{icon: 2});
					$("#coupon_confirm_btn").removeClass("disabled").removeAttr("disabled").val("生成券码并导出");
				}
			},error:function(){
				layer.msg("服务器网络繁忙",{icon: 2});
				$("#coupon_confirm_btn").removeClass("disabled").removeAttr("disabled").val("生成券码并导出");
			}
		});
	}
	function scopeClick(scope){
		if(scope==1){
			$("#goods_name_div").hide();
			$("#goods_name_input").val();
		}else if(scope==2){
			$("#goods_name_div").show();
		}
	}
	</script>
</body>
</html>